package com.julius.design.pattern.factory.normal;

import com.julius.design.pattern.factory.ab.AbstractFactory;
import com.julius.design.pattern.factory.ab.Order;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

/**
 * <p>
 *      用户工厂
 *      这里可以增加原型模式去优化获取对象的性能
 * </p>
 * @author 117028
 */
public class UserFactory extends AbstractFactory {

    private static final Map<String,UserPrototype> USER_MAP;
    
    static {
        Map<String,UserPrototype> map = new HashMap<>();
        map.put("b",new UserOfB());
        map.put("c",new UserOfC());
        USER_MAP = Collections.unmodifiableMap(map);
        
    }

    @Override
    public UserPrototype getUserObjectByName(String userObjectName) throws CloneNotSupportedException {

        if (Objects.isNull(userObjectName)) {
            return null;
        }
        return (UserPrototype) USER_MAP.get(userObjectName).clone();

    }

    @Override
    public Order getOrderObjectByName(String orderObjectName) {
        return null;
    }
}
